<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <base th:href="${#servletContext.getContextPath()+'/'}">

    <link rel="stylesheet" type="text/css" href="bootstrap-3.4.1/dist/css/bootstrap.css">
    <script type="text/javascript" src="jquery/jquery-3.6.1.min.js"></script>
    <script type="text/javascript" src="bootstrap-3.4.1/dist/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="jquery/http.js"></script>

    <script type="text/javascript">
        $(function () {
            $("#form-sysUser-add").submit(function () {
                submit("form-sysUser-add", "SystemUserServlet/add", function (data) {
                    // 这个函数服务端响应成功后调用
                    location.href = "/SystemUserServlet/list"
                });
                return false;
            });
            $("#username").change(function () {
                $.ajax({
                    url: "/SystemUserServlet/getUserByName",
                    type: "post",
                    data: $("#username").val(),
                    dataType: "json",
                    contentType: "application/json",
                    success: function (data) {
                        if (data == null) {
                            $("#msg").text("用户名可用").css("color", "green");
                            $("#addSubmit").removeAttr("disabled");
                        } else {
                            $("#msg").text("用户不可用").css("color", "red");
                            $("#addSubmit").attr("disabled","disabled");
                        }
                    }
                })
            })
        })
    </script>
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-md-4 col-md-offset-4">
            <h3 class="text-center text-info border-bottom pb-3">注&nbsp;&nbsp;册</h3>
            <form class="form-horizontal" id="form-sysUser-add">
                <div class="form-group">
                    <label class="col-sm-2 control-label">账号</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="username" name="username" value="toString"
                               placeholder="请输入用户名"><span id="msg"></span><br>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">密码</label>
                    <div class="col-sm-10">
                        <input type="password" class="form-control" name="password" value="toString" placeholder="密码">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">邮箱</label>
                    <div class="col-sm-10">
                        <input type="email" class="form-control" name="email" value="toString@qq.com"
                               placeholder="email...">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">生日</label>
                    <div class="col-sm-10">
                        <input type="date" class="form-control" name="birthday" value="2022-11-30"
                               placeholder="birthday...">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">性别</label>
                    <div class="radio">
                        <label class="radio-inline">
                            <input type="radio" name="sex" value="1">男
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="sex" value="0" checked>女
                        </label>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-default" id="addSubmit" disabled>添加</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
</html>